//do hilbert transform by FFT.
//hilber transform is phase shifter, it shift real signal by -90 degree.
//I learned the idea of doing hilber transformation by FFT from wikipeidia(search hilbert transform to get the answer).
//hilber transform shift negative frequency by 90 degree, shift positive frequency by -90 degree.
//so in frequency domain, multiply negative frequency by exp(%i*%pi/2) = i.
//multiplay positive fequency by exp(-%i*%pi/2) = -i
//xn is time domain real signal.
//xk is xn's DFT.
//assum xk's length is N, (0..N/2-1) associate with frequency > 0, (N/2..N-1) associate frequency < 0.
//xk_trans: multiply first half points in xk(0..N/2-1) by -i, multiply the second half points in xk by i.
//xn_trans: ifft of xk_trans
//the real part of xn_trans is time domain signal after hilbert transformation.

function block = hilbertTransformer_com(block, flag)
	//x_message(["size of block.z: ",string(size(block.z))])	
	//x_message(["size of block.insz(1): ", string(block.insz(1))])
	//x_message(["size of block.outptr(1): ", string(size(block.outptr(1)))])
	//x_message(["size of block.inptr(1): ", string(size(block.inptr(1)))])
	if flag == 1 then
    		block.outptr(1)(:) = block.z(:);
	elseif flag == 2 then
   		len = block.insz(1);
		xn = block.inptr(1)(:);
		xk = fft(xn);
		xk_trans = [xk(1:len/2)*(-%i); xk(len/2+1:len)*(%i)];
		xn_trans = ifft(xk_trans);
		block.z(:) = real(xn_trans);
	end
endfunction 
